package com.doubleview;


import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

/**
 * @author huchengchao@kuaishou.com
 * Created on 2021-11-19
 */
public class GroovyJSR223Example {

    public static void main(String[] args) {
        try {
            ScriptEngineManager factory = new ScriptEngineManager();
            ScriptEngine engine = factory.getEngineByName("groovy");
            String HelloLanguage = "def hello(language) {return \"Hello $language\"}";
            engine.eval(HelloLanguage);
            Invocable inv = (Invocable) engine;
            Object[] params = {new String("Groovy")};
            Object result = inv.invokeFunction("hello", params);
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
